package com.axend.lib_base.help.ble.enums

import com.axend.lib_base.R
import com.axend.lib_base.utils.CommUtils

/**
 * 蓝牙指令
 */
enum class BleCommandTag(
    private val id: Int,
    private val mark: ByteArray,
    private val markFixCommand: ByteArray = byteArrayOf(0x00,0x00,0x00,0x00),
    private val markName: String
) {
    //获取版本指令
    GET_VERSION(1, byteArrayOf(0x01, 0x00), byteArrayOf(0x01,0x00,0x00,0x00),markName = CommUtils.getString(
        R.string.app_command_tag_get_version)),

    //设置沙发门限 0:failed 1:success
    SET_SOFA_DOOR_SILL(4, byteArrayOf(0x04, 0x00), markName =CommUtils.getString(R.string.app_command_tag_set_thresh1)),

    //获取沙发门限
    GET_SOFA_DOOR_SILL(5, byteArrayOf(0x05, 0x00), byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_get_thresh1)),

    //控制沙发 1:沙发下降 2：沙发停止 3：沙发上升
    SET_SOFA_ACTION(7, byteArrayOf(0x07, 0x00), markName =CommUtils.getString(R.string.app_command_tag_control_sofa)),

    //设置沙发型号 0：failed 1:success
    SET_SOFA_MODEL(8, byteArrayOf(0x08, 0x00), markName =CommUtils.getString(R.string.app_command_tag_set_model)),

    //获取 sofa型号
    GET_SOFA_MODEL(9, byteArrayOf(0x09, 0x00), byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_get_model)),

    //设置沙发门限2
    SET_SOFA_DOOR_SILL2(11, byteArrayOf(0x0B, 0x00),markName =CommUtils.getString(R.string.app_command_tag_set_thresh2)),

    //获取 sofa门限
    GET_SOFA_DOOR_SILL2(12, byteArrayOf(0x0C, 0x00), byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_get_thresh2)),

    //开始学习
    SET_STUDY_START(13,byteArrayOf(0x0D,0x00),byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_start_study)),

    //结束学习
    SET_STUDY_END(14,byteArrayOf(0x0E,0x00),byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_stop_study)),

    //学习结果
    STUDY_RESULT(15,byteArrayOf(0x0F,0x00),markName =CommUtils.getString(R.string.app_command_tag_study_result)),

    //报警
    ALARM(16,byteArrayOf(0x10,0x00),markName =CommUtils.getString(R.string.app_command_tag_alarm)),

    /*固件升级部分单独处理*/
    //固件升级
    FW_UPGRADE_NOTIFY(20,byteArrayOf(0x00,0x01),markName =CommUtils.getString(R.string.app_command_tag_firmware_update)),

    //固件升级内容
    FW_CONTENT(21,byteArrayOf(0x01,0x01),markName =CommUtils.getString(R.string.app_command_tag_firmware_content)),

    //固件升级成功
    FW_UPDATE_SUCCESS(22,byteArrayOf(0x02,0x01),byteArrayOf(0x00,0x00,0x00,0x00),markName =CommUtils.getString(R.string.app_command_tag_firmware_update_result));


    companion object {
        fun fromId(id: Int): BleCommandTag? {
            return BleCommandTag.values().firstOrNull { it.id == id }
        }

        fun fromMark(mark: ByteArray): BleCommandTag? {
            return BleCommandTag.values().firstOrNull { it.mark.contentEquals(mark) }
        }
    }

    fun getMarkByteArray(): ByteArray = mark
    fun getMarkFixCommand(): ByteArray = markFixCommand

    fun getMarkName(): String = markName

}